<!DOCTYPE html>
<html lang="en" ng-app="stuManageApp">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="jquery-2.1.0.js"></script>
    <script src="angular1.5.8.js"></script>
    <script src="angular-route.min.js"></script>
    <script src="index.js"></script>  
    <style>
    		#box{
				width: 1000px;
				height:600px;
				border: 1px solid lightgoldenrodyellow;
				margin: 0 auto;
				background:lightgoldenrodyellow ;
				border-radius: 20px;
				text-align: center;
			}
	
    		h2{
    			text-align: center;
    			color:#A10000;
    		}
    </style>
</head>
<body>
	<div id="box">
    	<h2>学生管理系统</h2>
    	<div ng-view></div>

</body>
<script>
	$('.fa').click(function(){
    $('tbody').empty();//清空tbody的所有节点
 	var con=$('#ext').val();
 	if(con!=""){
         $.get('search',{name:con},function(arr){
             for(var i=0;i<arr.length;i++){
                var m=arr[i];
                var tr = $('<tr></tr>');
                $('<td><input type="checkbox" class="check"></td>').appendTo(tr);
                $('<td>' + m.num + '</td>').appendTo(tr);
                $('<td>' + m.name + '</td>').appendTo(tr);
                $('<td>' + m.price + '</td>').appendTo(tr);
                $('<td>' + m.brand + '</td>').appendTo(tr);
                $('<td>' + m.stock + '</td>').appendTo(tr);
                $("<td><a href='javascript:;' class='amendBtn'>修改</a></td>").appendTo(tr);
                tr.appendTo($('tbody'));
             }
         })
     }
 })

$scope.sou=function(){
			$http({
				method:'POST',
				url:'sou',
				headers:{'Content-Type': 'application/x-www-form-urlencoded'},
				data:'ext='+$scope.ext
			}).then(function(response){
				$rootScope.list=response.data;
				
			},function(response){
				alert('系统繁忙，请稍后再试');
			})
		}

app.post('/sou',urlParser,function(req,res){
	var n=req.body.ext;
	var reg=new RegExp(n,"i");
	var whereStr={username:{$regex:reg}};
	Student.find(whereStr,function(err,result){
		if(err){
			console.log('Error:'+err);
		}else{
			console.log('Res:'+result);
			res.send(result);
		}
	})
})






$scope.search=function(){
		var a=$scope.txt;
	
		$http({
			method: 'POST',
			url: 'search',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			}, //设置headers
			data: "txt=" + $scope.txt
		}).then(function(response) {
			
			console.log(response)
				$rootScope.list=response.data
		}, function(response) {
			alert("系统繁忙，请稍后再试");
		});
	}

高妍 2017/6/24 20:28:49
<div class="ss" align="center">
			<div class="search">
				<div class="searcha">
					<input type="text" class="text" ng-model="txt"/>
				</div>
				<div class="searchb" ng-click="search()">搜索</div>
			</div>
	</div>




var app=angular.module("stuManageApp",["ngRoute"]);
	app.config(function($routeProvider){//$routeProvider用于为应用注册路由
		$routeProvider.when("/list",{
			controller:listController,
			templateUrl:"list.html"
		}).when("/view/:id",{
			controller:detailController,
			templateUrl:"detail.html"
		}).otherwise({
			redirectTo:"/list"
		})
	})	
	
	function listController($scope,$http,$rootScope){
		$scope.sex="男";
//分页
     $scope.query=function(page){
     $http({
 		method:'GET',
	 		url:'list',
	 		params:{page:page}	 		
 	 	}).then(function(response){
 			 $rootScope.list=response.data.data;//获取数组
			 $scope.total=Math.ceil(response.data.total);//获取总页数
 		 },function(response){	
			 alert("系统繁忙，请稍后再试");
		 });
	 }
    //查询所有学生信息	 		
     $scope.query($scope.page);

		$scope.page=1;
        $scope.replace=function(page){
			if(page<1){
				page=1;return;
			}
			if(page>$scope.total){
				page=$scope.total;
				return;
			}
			$scope.query(page);
			$scope.page=page;
		}





		// $http({
		// 	method:'GET',
		// 	url:'list'
		// }).then(function(response){
		// 	$rootScope.list=response.data;
		// },function(response){
		// 	alert("系统繁忙，请稍后再试");
		// });

	//全选
	$scope.checks=false;
	$scope.checkAll=function(){
		$scope.checks=!$scope.checks;
	}

//全选删除
  $scope.delAll=function(){
	  var boxList=angular.element("input[type=checkbox]:checked");
	  if(confirm("确定要删除以上"+boxList.length+"条信息吗？"))
  {
    boxList.each(function(index,ele){
		console.log(ele.value);
			$scope.deleteUser(ele.value);
	})
  }
}
	//删除一个学生
	 $scope.del=function(index){
	 	if(!confirm("确定要删除吗")) return;
         $scope.deleteUser(index);
 }

	$scope.deleteUser=function(index){
		$http({
			method:'POST',
			url: 'del',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			}, //设置headers
			data: "id=" + index
		}).then(function(response){
			if(response.data=="success"){
				location.reload();
			}else{
				alert("系统繁忙，请稍后再试");
			}
		},function(response){
           alert("系统繁忙，请稍后再试");
		});
	} 	
	
  
	//添加
	$scope.save=function(){
		var obj={
			name:$scope.name,
			age:$scope.age,
			sex:$scope.sex
		}
		if($scope.id||$scope.id==0){
			obj.id=$scope.id;
		}
		$http({
			method:"POST",
			url:"save",
			headers:{
				"Content-Type":"application/x-www-form-urlencoded"
			},//设置headers
			data: $.param(obj)
		}).then(function(response){
			if(response.data=="success"){
				location.reload();
			}else{
				alert("系统繁忙，请稍后再试");
			}
			}, function(response){
				alert("系统繁忙,请稍后再试");
			});
		}
	










  //修改数据
     $scope.update=function(id,index){
		 var user=$rootScope.list[index];
		 $scope.name=user.username; 
		 $scope.age=parseInt(user.userage);
		 $scope.sex=user.usersex;
		 $scope.id=id;
	 }

//搜索
$scope.search=function(){
	var a=$scope.txt;
	$http({
			method: 'POST',
			url: 'search',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			}, //设置headers
			data: "txt=" + $scope.txt
		}).then(function(response) {			
			console.log(response)
				$rootScope.list=response.data
		}, function(response) {
			alert("系统繁忙，请稍后再试");
		});
}
}
	
	function detailController($scope,$routeParams,$rootScope){
		var id=$routeParams["id"];
		$scope.user=$rootScope.list[id];
	
}

</script>
</html>